<extend name="Public/header" />
<block name="main">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                商品列表 Tables
            </div>
            <!-- /.panel-heading -->
            <div class="panel-body">
                <table width="100%" class="table table-striped table-bordered table-hover" id="">
                    <thead>
                    <tr>
                        <th>No.</th>
                        <th>图片</th>
                        <th>状态</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach name="list" item="val">
                        <tr class="odd gradeX">
                             <td>{++$i}</td>
                            <td><img width="100" src="__ROOT__{$val.img}" alt=""></td>
                            <td class="center qj">{$val['state'] == 1 ? '启用' : '禁用'}</td>
                            <td class="center">{:date('Y-m-d H:i:s',$val['time'])}</td>
                            <td class="center">
                             <!--    <a href="" onclick="update({$vo.id})" class="btn btn-outline btn-primary">编辑</a> -->
                                <a href="javascript:void (0)" class="btn btn-outline btn-success" onclick="qj(this,{$val['id']})">{$val['state'] == 1 ? '隐藏' : '启用'}</a>
                                <a href="{:U('picdel',array('id'=>$val['id']))}"  class="btn btn-outline btn-danger" >删除</a>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
                <!-- /.table-responsive -->
                <div class="row"><div class="col-sm-6"></div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                            <div class="pages" style="margin: 0px auto;text-align: center;">
                                {$page}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.panel-body -->
        </div>
        <!-- /.panel -->
    </div>

</block>
<block name='js'>

    <!-- <script type="text/javascript">window.url = '__URL__/Pic'</script>-->
    <!-- ue_end -->
    <script type="text/javascript" src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript">
        var No = 1;
        window.url = '__URL__/pic/id/{$Think.get.id}/t/add';
        $('#add').click(function(){

            $('#form').attr('action','__URL__/pic/t/add');
            $('#form input').empty();
            if ($(this).html() == '取消') {
                $(this).html('添加新的图片');
                $('#Doadd').hide(); return ;
            }
            $(this).html('取消');
            $('.upload').addClass('block');
            $('.upload').removeClass('none');

            $('#Doadd').show();
            
        })
        function update(id)
        {
            

            $('#form').attr('action','__URL__/pic/t/update');
            $('#form input').val('');
            $('#add').html('取消');
            $('#Doadd').show();
            $('.upload').addClass('none');
            $('.upload').removeClass('block');
            $('input[name=id]').val(id)
            $('body,html').animate({'scrollTop':0},100) 
        }
            
        function qj(tha,id) {
            $.ajax({
                type: 'POST',
                data:{id:id},
                url: '{:U("picqj")}',
                success: function(dat){
                    console.dir(dat);
                    dat = JSON.parse(dat);
                    alert(dat.message)
                    if(dat.state == 1)
                    {
                        $(tha).html('隐藏')
                        $(tha).parent().parent().find('.qj').html('启用')
                    }else if(dat.state == 2){
                        $(tha).html('启用')
                        $(tha).parent().parent().find('.qj').html('隐藏')
                    }
                },
                error:function () {
                    alert('系统错误')
                }
            })
        }
   

        // var t = $('#dataTables-example').DataTable(
    
        // );
    </script>
    <script type="text/javascript" src="__PUBLIC__/weber/webuploader.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/weber/upload.js"></script> 
</block>